package com.byd.sealmanage.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.byd.sealmanage.config.CommonResultOutput;
import com.byd.sealmanage.dao.mybatis.*;
import com.byd.sealmanage.modal.bo.ProcessParamVO;
import com.byd.sealmanage.modal.po.*;
import com.byd.sealmanage.service.ProcessManageService;
import com.byd.sealmanage.util.JsonUtil;
import com.byd.sealmanage.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class ProcessManageServiceImpl implements ProcessManageService {

    @Autowired
    private TbProcessMapper tbProcessMapper;

    @Autowired
    private TbDivisionSealMapper tbDivisionSealMapper;

    @Autowired
    private TbProcessNodeMapper tbProcessNodeMapper;

    @Autowired
    private TbProcessRouteMapper tbProcessRouteMapper;

    @Autowired
    private TbUserMapper tbUserMapper;


    /**
     * 获取我的申请列表数据
     * @return
     */
    @Override
    public JSONObject getMyApplyDataService(ProcessParamVO processParamVO) {
        CommonResultOutput commonResultOutput;
        JSONObject jsonObject = new JSONObject();
        try{
            int begin = (processParamVO.getPage() - 1) * processParamVO.getPageSize();
            processParamVO.setBegin(begin);
            int totalCount = tbProcessMapper.selectApplyCount(processParamVO);
            jsonObject.put("total",totalCount);
            if(totalCount > 0){
                List<ProcessParamVO> applyData = tbProcessMapper.selectApplyData(processParamVO);
                jsonObject.put("rows",applyData);
                commonResultOutput = new CommonResultOutput(200,"查询成功",jsonObject);
            }else{
                commonResultOutput = new CommonResultOutput(999,"查询结果为空",jsonObject);
            }
        }catch(Exception e){
            log.info("获取我的申请数据接口出现异常");
            log.info(e.toString());
            commonResultOutput = new CommonResultOutput(999,"执行出现异常",jsonObject);
        }
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    /**
     * 获取流程详情页基本信息数据
     * @param trackId
     * @return
     */
    @Override
    public JSONObject getDetailBasicInfo(String trackId) {
        CommonResultOutput commonResultOutput;
        JSONObject jsonObject = new JSONObject();
        try{
            ProcessParamVO processParamVO = tbProcessMapper.selectBasicInfo(trackId);
            jsonObject.put("processInfo",processParamVO);
            commonResultOutput = new CommonResultOutput("0000",jsonObject);
        }catch (Exception e){
            log.info("获取流程详情信息接口页面出现异常");
            log.info(e.toString());
            commonResultOutput = new CommonResultOutput("9999","执行出现异常");
        }
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    /**
     * 获取刻制申请相关的印章信息
     * @param trackId
     * @return
     */
    @Override
    public JSONObject getApplySealInfo(String trackId) {
        CommonResultOutput commonResultOutput;
        JSONObject jsonObject = new JSONObject();
        try{
            List<TbDivisionSeal> engraveApplyParamVos = tbDivisionSealMapper.selectApplySealInfo(trackId);
            for(TbDivisionSeal engraveApplyParamVo1 : engraveApplyParamVos){
                String[] sealPictures = engraveApplyParamVo1.getSealPattern().split("sealPicture");
                engraveApplyParamVo1.setSealPattern("localFile" + sealPictures[1]);
            }
            jsonObject.put("sealInfo",engraveApplyParamVos);
            commonResultOutput = new CommonResultOutput("0000",jsonObject);
        }catch (Exception e){
            log.info("获取刻制申请相关色板接口出现异常");
            log.info(e.toString());
            commonResultOutput = new CommonResultOutput("9999","执行出现异常");
        }
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    /**
     * 获取流程节点相关信息
     * @param trackId
     * @return
     */
    @Override
    public JSONObject getProcessNodeInfo(String trackId) {
        CommonResultOutput commonResultOutput;
        JSONObject jsonObject = new JSONObject();
        try{
            List<TbProcessNode> processNodes = tbProcessNodeMapper.selectProcessNode(trackId);
            jsonObject.put("processNodeInfo",processNodes);
            commonResultOutput = new CommonResultOutput("0000",jsonObject);
        }catch(Exception e){
            log.info("获取流程详情页接口出现异常");
            log.info(e.toString());
            commonResultOutput = new CommonResultOutput("9999","执行出现异常");
        }
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    /**
     * 获取我的待办页面数据
     * @param processParamVO
     * @return
     */
    @Override
    public JSONObject getMyNotDoTableData(ProcessParamVO processParamVO) {
        CommonResultOutput commonResultOutput;
        JSONObject jsonObject = new JSONObject();
        try{
            int begin = ( processParamVO.getPage() - 1 ) * processParamVO.getPageSize();
            processParamVO.setBegin(begin);
            int dataCount = tbProcessMapper.getMyNotDoDataCount(processParamVO);
            jsonObject.put("total",dataCount);
            if(dataCount > 0){
                List<ProcessParamVO> applyData = tbProcessMapper.getMyNotDoDataList(processParamVO);
                jsonObject.put("rows",applyData);
                commonResultOutput = new CommonResultOutput(200,"查询成功",jsonObject);
            }else{
                commonResultOutput = new CommonResultOutput(999,"查询结果为空",jsonObject);
            }
        }catch (Exception e){
            log.info("我的待办页面接口出现异常");
            log.info(e.toString());
            commonResultOutput = new CommonResultOutput(999,"执行出现异常",jsonObject);
        }
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    /**
     * 刻制申请同意流程
     * @param map
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject agreeProcessService(Map<String,String> map,TbUser loginUser) {
        CommonResultOutput commonResultOutput;
        Date date = new Date();
        try{
            //流程信息
            ProcessParamVO processInfo = tbProcessMapper.selectWorkingProcess(map.get("trackId"));
            if(!loginUser.getJobnumber().equals(processInfo.getApprovePeople())){
                commonResultOutput = new CommonResultOutput(999,"流程异常，请刷新页面重试");
                return JsonUtil.toJSONObject(commonResultOutput);
            }
            //查询流程路线.
            List<TbProcessRoute> processRoutes = tbProcessRouteMapper.getProcessRouteByType(processInfo.getProcessType());
            if(processRoutes.get(processRoutes.size() - 1).getNodeName().equals(processInfo.getApproveNode())){
                //流程结案
                //更新当前结案节点
                TbProcessNode tbProcessNode = new TbProcessNode();
                tbProcessNode.setApproveTime(date);
                tbProcessNode.setApproveResult("15");
                tbProcessNode.setApproveRemark(map.get("approveRemark"));
                tbProcessNode.setNodeState("0");
                Example nodeUpdate = new Example(TbProcessNode.class);
                Example.Criteria nodeCriteria = nodeUpdate.createCriteria();
                nodeCriteria.andEqualTo("trackId",map.get("trackId"));
                nodeCriteria.andEqualTo("nodeState","1");
                tbProcessNodeMapper.updateByExampleSelective(tbProcessNode,nodeUpdate);
                //更行流程记录表
                TbProcess tbProcess = new TbProcess();
                tbProcess.setApproveNumber(" ");
                tbProcess.setApproveName(" ");
                tbProcess.setApproveEmail(" ");
                tbProcess.setState("15");
                Example processUpdate = new Example(TbProcess.class);
                Example.Criteria criteria = processUpdate.createCriteria();
                criteria.andEqualTo("trackId",map.get("trackId"));
                tbProcessMapper.updateByExampleSelective(tbProcess,processUpdate);
                //修改事业部色板信息中状态
                TbDivisionSeal tbDivisionSeal = new TbDivisionSeal();
                tbDivisionSeal.setStatus("2");
                Example sealUpdate = new Example(TbDivisionSeal.class);
                Example.Criteria sealCriteria = sealUpdate.createCriteria();
                sealCriteria.andEqualTo("taskId",map.get("trackId"));
                tbDivisionSealMapper.updateByExampleSelective(tbDivisionSeal,sealUpdate);
            }else{
                //更新当前节点
                TbProcessNode tbProcessNode = new TbProcessNode();
                tbProcessNode.setApproveTime(date);
                tbProcessNode.setApproveResult("10");
                tbProcessNode.setApproveRemark(map.get("approveRemark"));
                tbProcessNode.setNodeState("0");
                Example nodeUpdate = new Example(TbProcessNode.class);
                Example.Criteria nodeCriteria = nodeUpdate.createCriteria();
                nodeCriteria.andEqualTo("trackId",map.get("trackId"));
                nodeCriteria.andEqualTo("nodeState","1");
                tbProcessNodeMapper.updateByExampleSelective(tbProcessNode,nodeUpdate);
                //流程流向下一节点
                int  nextRouteOrder = 0;
                for (TbProcessRoute tbProcessRoute : processRoutes){
                    if (tbProcessRoute.getNodeName().equals(processInfo.getApproveNode())) {
                        nextRouteOrder = Integer.parseInt(tbProcessRoute.getApprovalOrder());
                        break;
                    }
                }
                TbProcessNode nextNode = new TbProcessNode();
                nextNode.setNodeName(processRoutes.get(nextRouteOrder).getNodeName());
                //查找审批人
                String email;
                TbProcess tbProcess = new TbProcess();
                if(!StringUtil.isNullString(map.get("approvePeople"))){
                    String[] approvePeopleInfo = map.get("approvePeople").split("-");
                    nextNode.setConfirmNumber(approvePeopleInfo[0]);
                    nextNode.setConfirmName(approvePeopleInfo[1]);
                    tbProcess.setApproveNumber(approvePeopleInfo[0]);
                    tbProcess.setApproveName(approvePeopleInfo[1]);
                    email = tbUserMapper.getUserByJobNumber(approvePeopleInfo[0],null).getEmail();
                }else{
                    //查找地区管理员
                    TbUser tbUser = tbUserMapper.selectPlaceManager(map.get("place"));
                    nextNode.setConfirmNumber(tbUser.getJobnumber());
                    nextNode.setConfirmName(tbUser.getUsername());
                    tbProcess.setApproveNumber(tbUser.getJobnumber());
                    tbProcess.setApproveName(tbUser.getUsername());
                    email = tbUser.getEmail();
                }
                nextNode.setConfirmEmail(email);
                nextNode.setReceiveTime(date);
                nextNode.setApproveResult("1");
                nextNode.setNodeState("1");
                nextNode.setTrackId(map.get("trackId"));
                tbProcessNodeMapper.insertSelective(nextNode);
                //更新流程记录表
                tbProcess.setApproveEmail(email);
                Example example = new Example(TbProcess.class);
                Example.Criteria criteria = example.createCriteria();
                criteria.andEqualTo("trackId",map.get("trackId"));
                tbProcessMapper.updateByExampleSelective(tbProcess,example);
            }
            commonResultOutput = new CommonResultOutput(200,"流程审批成功");
        }catch(Exception e){
            log.info("同意流程接口出现异常");
            log.info(e.toString());
            commonResultOutput = new CommonResultOutput(999,"执行出现异常");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    /**
     * 刻制申请驳回流程
     * @param map
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject rejectProcessService(Map<String, String> map,TbUser loginUser) {
        CommonResultOutput commonResultOutput;
        Date date = new Date();
        try{
            //流程信息
            ProcessParamVO processInfo = tbProcessMapper.selectWorkingProcess(map.get("trackId"));
            if(!loginUser.getJobnumber().equals(processInfo.getApprovePeople())){
                commonResultOutput = new CommonResultOutput(999,"流程异常，请刷新页面重试");
                return JsonUtil.toJSONObject(commonResultOutput);
            }
            //查询流程路线
            List<TbProcessRoute> processRoutes = tbProcessRouteMapper.getProcessRouteByType(processInfo.getProcessType());
            //更新当前节点
            TbProcessNode tbProcessNode = new TbProcessNode();
            tbProcessNode.setApproveTime(date);
            tbProcessNode.setApproveRemark(map.get("approveRemark"));
            tbProcessNode.setApproveResult("2");
            tbProcessNode.setNodeState("0");
            Example nodeUpdate = new Example(TbProcessNode.class);
            Example.Criteria criteria = nodeUpdate.createCriteria();
            criteria.andEqualTo("trackId",map.get("trackId"));
            criteria.andEqualTo("nodeState","1");
            tbProcessNodeMapper.updateByExampleSelective(tbProcessNode,nodeUpdate);
            //插入新节点
            TbProcessNode newNode = new TbProcessNode();
            newNode.setNodeName(processRoutes.get(0).getNodeName());
            newNode.setConfirmNumber(processInfo.getApplyNumber());
            newNode.setConfirmName(processInfo.getApplyName());
            newNode.setConfirmEmail(processInfo.getApplyEmail());
            newNode.setReceiveTime(date);
            newNode.setApproveResult("1");
            newNode.setNodeState("1");
            newNode.setTrackId(map.get("trackId"));
            tbProcessNodeMapper.insertSelective(newNode);
            //更新流程记录表
            TbProcess tbProcess = new TbProcess();
            tbProcess.setApproveNumber(processInfo.getApplyNumber());
            tbProcess.setApproveName(processInfo.getApplyName());
            tbProcess.setApproveEmail(processInfo.getApplyEmail());
            tbProcess.setState("2");
            Example processUpdate = new Example(TbProcess.class);
            Example.Criteria processCriteria = processUpdate.createCriteria();
            processCriteria.andEqualTo("trackId",map.get("trackId"));
            tbProcessMapper.updateByExampleSelective(tbProcess,processUpdate);
            commonResultOutput = new CommonResultOutput(200,"流程审批成功");
        }catch(Exception e){
            log.info("刻制申请驳回流程接口出现异常");
            log.info(e.toString());
            commonResultOutput = new CommonResultOutput(999,"执行出现异常");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    /**
     * 流程驳回后重新提交
     * @param map
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject submitAgainService(Map<String, String> map,TbUser loginUser) {
        CommonResultOutput commonResultOutput;
        Date date = new Date();
        try{
            //流程信息
            ProcessParamVO processInfo = tbProcessMapper.selectWorkingProcess(map.get("trackId"));
            if(!loginUser.getJobnumber().equals(processInfo.getApprovePeople())){
                commonResultOutput = new CommonResultOutput(999,"流程异常，请刷新重试");
                return JsonUtil.toJSONObject(commonResultOutput);
            }
            //查询流程路线
            List<TbProcessRoute> processRoutes = tbProcessRouteMapper.getProcessRouteByType(processInfo.getProcessType());
            //更新当前节点
            TbProcessNode tbProcessNode = new TbProcessNode();
            tbProcessNode.setApproveTime(date);
            tbProcessNode.setApproveRemark("重新提交");
            tbProcessNode.setApproveResult("10");
            tbProcessNode.setNodeState("0");
            Example nodeUpdate = new Example(TbProcessNode.class);
            Example.Criteria criteria = nodeUpdate.createCriteria();
            criteria.andEqualTo("trackId",map.get("trackId"));
            criteria.andEqualTo("nodeState","1");
            tbProcessNodeMapper.updateByExampleSelective(tbProcessNode,nodeUpdate);
            //添加下一节点
            TbProcessNode nextNode = new TbProcessNode();
            nextNode.setNodeName(processRoutes.get(1).getNodeName());
            String receiveApprove = map.get("approvePeople");
            String[] approvePeople = receiveApprove.split("-");
            nextNode.setConfirmNumber(approvePeople[0]);
            nextNode.setConfirmName(approvePeople[1]);
            TbUser confirmUser = tbUserMapper.getUserByJobNumber(approvePeople[0],"1");
            nextNode.setConfirmEmail(confirmUser.getEmail());
            nextNode.setReceiveTime(date);
            nextNode.setApproveResult("1");
            nextNode.setNodeState("1");
            nextNode.setTrackId(map.get("trackId"));
            tbProcessNodeMapper.insertSelective(nextNode);
            //不同的流程在此处有不同的步骤需执行：刻制申请流程-将之前申请时录入的刻制印章删除，重新添加新的刻制印章
            tbDivisionSealMapper.deleteEngraveSeal(map.get("trackId"));
            List<TbDivisionSeal> sealInfo = JSON.parseArray(map.get("sealInfo"), TbDivisionSeal.class);
            for(TbDivisionSeal item : sealInfo){
                item.setTaskId(map.get("trackId"));
                item.setStatus("1");
                item.setPlace(processInfo.getPlace());
                item.setFactory(processInfo.getApplyFactory());
//                item.setDepartment(processInfo.getApplyDepartment());
                String[] sealPatternTime = item.getSealPattern().split("localFile");
                if(sealPatternTime.length == 2){
                    item.setSealPattern("D:/fuming/sealPicture" + sealPatternTime[1]);
                }
            }
            tbDivisionSealMapper.insertSealList(sealInfo);
            //更新流程记录
            TbProcess tbProcess = new TbProcess();
            tbProcess.setApplyReason(map.get("applyReason"));
            tbProcess.setApproveNumber(approvePeople[0]);
            tbProcess.setApproveName(approvePeople[1]);
            tbProcess.setApproveEmail(confirmUser.getEmail());
            tbProcess.setState("1");
            Example processUpdate = new Example(TbProcess.class);
            Example.Criteria processCriteria = processUpdate.createCriteria();
            processCriteria.andEqualTo("trackId",map.get("trackId"));
            tbProcessMapper.updateByExampleSelective(tbProcess,processUpdate);
            commonResultOutput = new CommonResultOutput(200,"提交成功");
        }catch(Exception e){
            log.info("流程驳回重新提交接口出现异常");
            log.info(e.toString());
            commonResultOutput = new CommonResultOutput(999,"执行出现异常");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    /**
     * 流程转交
     * @param map
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject changeApprovePeopleService(Map<String, String> map,TbUser loginUser) {
        CommonResultOutput commonResultOutput;
        Date date = new Date();
        try{
            //流程信息
            ProcessParamVO processInfo = tbProcessMapper.selectWorkingProcess(map.get("trackId"));
            if(!loginUser.getJobnumber().equals(processInfo.getApprovePeople())){
                commonResultOutput = new CommonResultOutput(999,"流程异常，请刷新重试");
                return JsonUtil.toJSONObject(commonResultOutput);
            }
            //更新当前节点
            TbProcessNode tbProcessNode = new TbProcessNode();
            tbProcessNode.setApproveTime(date);
            tbProcessNode.setApproveRemark(map.get("approveRemark"));
            tbProcessNode.setApproveResult("3");
            tbProcessNode.setNodeState("0");
            Example nodeUpdate = new Example(TbProcessNode.class);
            Example.Criteria criteria = nodeUpdate.createCriteria();
            criteria.andEqualTo("trackId",map.get("trackId"));
            criteria.andEqualTo("nodeState","1");
            tbProcessNodeMapper.updateByExampleSelective(tbProcessNode,nodeUpdate);
            //增加新节点
            TbProcessNode nextNode = new TbProcessNode();
            nextNode.setTrackId(map.get("trackId"));
            nextNode.setNodeName(processInfo.getApproveNode());
            String[] confirmPeople = map.get("changePeople").split("-");
            nextNode.setConfirmNumber(confirmPeople[0]);
            nextNode.setConfirmName(confirmPeople[1]);
            TbUser tbUser = tbUserMapper.getUserByJobNumber(confirmPeople[0],"1");
            nextNode.setConfirmEmail(tbUser.getEmail());
            nextNode.setReceiveTime(date);
            nextNode.setApproveResult("1");
            nextNode.setNodeState("1");
            tbProcessNodeMapper.insertSelective(nextNode);
            //更新流程记录
            TbProcess tbProcess = new TbProcess();
            tbProcess.setApproveNumber(confirmPeople[0]);
            tbProcess.setApproveName(confirmPeople[1]);
            tbProcess.setApproveEmail(tbUser.getEmail());
            Example processUpdate = new Example(TbProcess.class);
            Example.Criteria processCriteria = processUpdate.createCriteria();
            processCriteria.andEqualTo("trackId",map.get("trackId"));
            tbProcessMapper.updateByExampleSelective(tbProcess,processUpdate);
            commonResultOutput = new CommonResultOutput(200,"审批成功");
        }catch (Exception e){
            log.info("流程转交接口出现异常");
            log.info(e.toString());
            commonResultOutput = new CommonResultOutput(999,"执行出现异常");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    /**
     * 流程撤回
     * @param map
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject backProcessService(Map<String,String> map) {
        CommonResultOutput commonResultOutput;
        Date date = new Date();
        try{
            //流程信息
            ProcessParamVO processInfo = tbProcessMapper.selectWorkingProcess(map.get("trackId"));
            //查询流程路线
            List<TbProcessRoute> processRoutes = tbProcessRouteMapper.getProcessRouteByType(processInfo.getProcessType());
            if(!processInfo.getApproveNode().equals(processRoutes.get(1).getNodeName())){
                commonResultOutput = new CommonResultOutput(999,"流程异常，请刷新重试");
                return JsonUtil.toJSONObject(commonResultOutput);
            }
            //删除当前节点
            tbProcessNodeMapper.deleteNode(map.get("trackId"),"1");
            //增加当前新节点
            TbProcessNode nextNode = new TbProcessNode();
            nextNode.setNodeName(processRoutes.get(0).getNodeName());
            nextNode.setConfirmNumber(processInfo.getApplyNumber());
            nextNode.setConfirmName(processInfo.getApplyName());
            nextNode.setConfirmEmail(processInfo.getApplyEmail());
            nextNode.setReceiveTime(date);
            nextNode.setApproveResult("1");
            nextNode.setNodeState("1");
            nextNode.setTrackId(map.get("trackId"));
            tbProcessNodeMapper.insertSelective(nextNode);
            //更新流程记录
            TbProcess tbProcess = new TbProcess();
            tbProcess.setApproveNumber(processInfo.getApplyNumber());
            tbProcess.setApproveName(processInfo.getApplyName());
            tbProcess.setApproveEmail(processInfo.getApplyEmail());
            tbProcess.setState("4");
            Example processUpdate = new Example(TbProcess.class);
            Example.Criteria processCriteria = processUpdate.createCriteria();
            processCriteria.andEqualTo("trackId",map.get("trackId"));
            tbProcessMapper.updateByExampleSelective(tbProcess,processUpdate);
            commonResultOutput = new CommonResultOutput(200,"撤回成功");
        }catch(Exception e){
            log.info("流程撤回接口出现异常");
            log.info(e.toString());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            commonResultOutput = new CommonResultOutput(999,"执行出现异常");
        }
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    /**
     * 流程废止
     * @param map
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject stopProcessService(Map<String, String> map,TbUser loginUser) {
        CommonResultOutput commonResultOutput;
        try{
            String trackId = map.get("trackId");
            //流程信息
            ProcessParamVO processInfo = tbProcessMapper.selectWorkingProcess(trackId);
            if(!loginUser.getJobnumber().equals(processInfo.getApprovePeople())){
                commonResultOutput = new CommonResultOutput(999,"流程异常，请刷新重试");
                return JsonUtil.toJSONObject(commonResultOutput);
            }
            //删除流程记录
            tbProcessMapper.deleteProcess(trackId);
            //删除流程节点
            tbProcessNodeMapper.deleteNode(trackId,null);
            //删除印章数据
            tbDivisionSealMapper.deleteEngraveSeal(trackId);
            commonResultOutput = new CommonResultOutput(200,"流程废止成功");
        }catch (Exception e){
            log.info("流程废止接口出现异常");
            log.info(e.toString());
            commonResultOutput = new CommonResultOutput(999,"执行出现异常");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    /**
     * 获取我的审批页面数据
     * @param processParamVO
     * @return
     */
    @Override
    public JSONObject getMyApprovedPageData(ProcessParamVO processParamVO) {
        CommonResultOutput commonResultOutput;
        JSONObject jsonObject = new JSONObject();
        try{
            int begin = (processParamVO.getPage() - 1) * processParamVO.getPageSize();
            processParamVO.setBegin(begin);
            int dataCount = tbProcessMapper.selectMyApproveDataCount(processParamVO);
            jsonObject.put("total",dataCount);
            if(dataCount > 0){
                List<ProcessParamVO> applyData = tbProcessMapper.selectMyApproveData(processParamVO);
                jsonObject.put("rows",applyData);
                commonResultOutput = new CommonResultOutput(200,"查询成功",jsonObject);
            }else{
                commonResultOutput = new CommonResultOutput(999,"查询结果为空",jsonObject);
            }
        }catch (Exception e){
            log.info("获取我的审批页面数据出现异常");
            log.info(e.toString());
            commonResultOutput = new CommonResultOutput(999,"执行出现异常");
        }
        return JsonUtil.toJSONObject(commonResultOutput);
    }


}
